package com.corechina.apex_osswords.controller;


import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.SysLog;
import com.corechina.apex_osswords.domain.dto.SysUserGroupsDto;
import com.corechina.apex_osswords.domain.entity.SysUserGroups;
import com.corechina.apex_osswords.service.ISysUserGroupsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户分组表 前端控制器
 * </p>
 *
 * @author cc
 * @since 2022-03-03
 */
@Api(tags = "用户组管理")
@RestController
@RequestMapping("/sys/userGroups")
public class SysUserGroupsController {
    @Autowired
    private ISysUserGroupsService iSysUserGroupsService;

    @SysLog("新增用户组")
    @PostMapping("/add")
//    @RequiresPermissions("sys:userGroups:add")
    @ApiOperation("新增用户组")
    public Response add(@RequestBody SysUserGroupsDto sysUserGroupsDto) {
        iSysUserGroupsService.addOrUpdate(sysUserGroupsDto);
        return Response.ok();
    }

    @SysLog("编辑用户组")
    @PutMapping("/update")
//    @RequiresPermissions("sys:userGroups:update")
    @ApiOperation("编辑用户组信息")
    public Response update(@RequestBody SysUserGroupsDto sysUserGroupsDto) {
        iSysUserGroupsService.addOrUpdate(sysUserGroupsDto);
        return Response.ok();
    }

    @SysLog("删除用户组")
    @DeleteMapping("/del")
//    @RequiresPermissions("sys:userGroups:del")
    @ApiOperation("删除用户组信息")
    public Response del(Integer id) {
        iSysUserGroupsService.del(id);
        return Response.ok();
    }

    @GetMapping("/queryUserGroupsAllList")
//    @RequiresPermissions("sys:userGroups:getList")
    @ApiOperation("查询用户组列表")
    public Response getList() {
        List<SysUserGroups> sysUserGroups = iSysUserGroupsService.getList();
        return Response.ok(sysUserGroups, sysUserGroups.size());
    }

    @GetMapping("/getOne")
//    @RequiresPermissions("sys:userGroups:getList")
    @ApiOperation("获取详情")
    public Response getOne(Integer id) {
        return Response.ok(iSysUserGroupsService.getOne(id));
    }
}

